/**
 *
 */
package hichecker.ui.custom_views.passing;

import hichecker.controller.Config;
import hichecker.ui.components.icon_factory.IconFactory;
import hichecker.ui.components.icon_factory.IconFactory.IconType;
import hichecker.ui.custom_views.passing.PassingCondition.ConditionType;
import hichecker.ui.general_views.container_panel.navigation.NavigationCellRenderer;
import hichecker.university.UniversityPart;

import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JToolBar;

/**
 *
 */
public class StatementToolBar extends JToolBar {

	private UniversityPart selected;
	private JComboBox objectBox;
	private JComboBox typeBox;
	private DefaultComboBoxModel typeModel;

	/**
	 *
	 */
	public StatementToolBar(UniversityPart part) {
		// TODO Auto-generated constructor stub

		setFloatable(false);
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
		add(IconFactory.getIconButton("R", Config.TOOLTIP_REMOVE_CONDITION, IconType.REMOVE, new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
//				passingCondition.removeCondition(reference);
//				createView(passingCondition);
			}
		}));


		// Combobox for the condition object
		DefaultComboBoxModel objectModel = new DefaultComboBoxModel();
		objectModel.addElement(part);
		for (UniversityPart sub : part.getSubParts())
			objectModel.addElement(sub);

		objectBox = new JComboBox(objectModel);
		objectBox.setRenderer(new NavigationCellRenderer());

		selected = part;
		objectBox.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				selected = (UniversityPart) e.getItem();
				changeTypeBox();
			}
		});
		add(objectBox);

		// Combobox for the condition type
		typeModel = new DefaultComboBoxModel();
		changeTypeBox();
		typeBox = new JComboBox(typeModel);
		add(typeBox);

		// Field for the value
		JTextField valueField = new JTextField();
		add(valueField);

	}

	private void changeTypeBox() {
		typeModel.removeAllElements();
		for (ConditionType type : selected.getPossibleConditions())
			typeModel.addElement(type);
	}

}
